import {
  BaseEntity,
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity()
export class IBaseEntity extends BaseEntity {
  constructor(partial: Partial<IBaseEntity> = {}) {
    super();
    Object.assign(this, partial);
  }

  @Column('bigint', { primary: true, name: 'id' })
  @PrimaryGeneratedColumn()
  id: number;

  @Column('nvarchar', { name: 'create_user', nullable: true, length: 255 })
  createUser: string | null;

  @Column('nvarchar', { name: 'update_user', nullable: true, length: 255 })
  updateUser: string | null;
  @CreateDateColumn({
    name: 'create_time',
    nullable: true,
    type: 'datetime2',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createTime: Date | null;
  @UpdateDateColumn({
    name: 'update_time',
    nullable: true,
    type: 'datetime2',
    default: () => 'CURRENT_TIMESTAMP',
  })
  updateTime: Date | null;
  @Column('bigint', { name: 'create_by', nullable: true })
  createBy: number | null;
  @Column('bigint', { name: 'update_by', nullable: true })
  updateBy: number | null;
  @DeleteDateColumn({ name: 'delete_time', nullable: true })
  deletedTime: Date | null;
}
